package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()){
            String sql = "INSERT INTO article(title,content) "+
                         "VALUES(?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入标题");
            String title = scanner.nextLine();
            System.out.println("请输入内容");
            String content = scanner.nextLine();
            ps.setString(1,title);
            ps.setString(2,content);
            ps.execute();
            System.out.println("插入成功");
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}
